home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_13_02
/
pugh
/
trysort.cpp
< prev
Wrap
C/C++ Source or Header
|
1994-12-11
|
808b
|
38 lines
#include <stdlib.h>
int compare_function(const void * a, const void * b);
class A
{
private:
struct DataType
{
double x,y;
} * data;
int size;
public:
A();
A(int n, double *x, double *y);
void sort();
};
void A::sort()
{
qsort (data, size, sizeof(DataType), compare_function);
}
int compare_function(const void * a, const void * b)
{
const DataType *first = (DataType*) a;
const DataType *second = (DataType*) b;
// Ought these declaration be as follows ?
// const A::DataType *first = (A::DataType*) a;
// const A::DataType *second = (A::DataType*) b;
if (first->x > second->x)
return 1;
else if (first->x < second->x)
return -1;
else
return 0;
}